package com.ruoyi.project.cms.controller;

import java.util.List;

import com.ruoyi.project.common.utils.SubscribeMsgUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cms.domain.WxSubscribeMsg;
import com.ruoyi.project.cms.service.IWxSubscribeMsgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 小程序订阅消息模板维护Controller
 * 
 * @author ruoyi
 * @date 2020-09-10
 */
@RestController
@RequestMapping("/cms/templatemsg")
public class WxSubscribeMsgController extends BaseController
{
    @Autowired
    private IWxSubscribeMsgService wxSubscribeMsgService;
    @Autowired
    private SubscribeMsgUtils subscribeMsgUtils;

    /**
     * 查询小程序订阅消息模板维护列表
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxSubscribeMsg wxSubscribeMsg)
    {
        startPage();
        List<WxSubscribeMsg> list = wxSubscribeMsgService.selectWxSubscribeMsgList(wxSubscribeMsg);
        return getDataTable(list);
    }


    /**
     * 获取小程序订阅消息模板维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxSubscribeMsgService.selectWxSubscribeMsgById(id));
    }

    /**
     * 新增小程序订阅消息模板维护
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:add')")
    @Log(title = "小程序订阅消息模板维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxSubscribeMsg wxSubscribeMsg)
    {
        return toAjax(wxSubscribeMsgService.insertWxSubscribeMsg(wxSubscribeMsg));
    }

    /**
     * 修改小程序订阅消息模板维护
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:edit')")
    @Log(title = "小程序订阅消息模板维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxSubscribeMsg wxSubscribeMsg)
    {
        return toAjax(wxSubscribeMsgService.updateWxSubscribeMsg(wxSubscribeMsg));
    }

    /**
     * 删除小程序订阅消息模板维护
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:remove')")
    @Log(title = "小程序订阅消息模板维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxSubscribeMsgService.deleteWxSubscribeMsgByIds(ids));
    }

    /**
     * 测试订阅模版消息
     */
    @PreAuthorize("@ss.hasPermi('cms:templatemsg:query')")
    @GetMapping(value = "/test/{code}/{openId}")
    public AjaxResult testSubscribeMsg(@PathVariable("code") String code,@PathVariable("openId")String openId)
    {
        WxSubscribeMsg wsm = wxSubscribeMsgService.selectByCode(code);
     /*   subscribeMsgUtils.sendMsgTemplate(openId,wsm);*/
        return AjaxResult.success();
    }
}
